import request from '@/utils/axios/axios-service.ts'

/**
 * 店铺接口
 */
export const shopList = (params: any) => request.get('/shop/info/list', {params: params})
export const shopInfo = (id: number) => request.get('/shop/info/info/' + id)
export const shopSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/shop/info/create' : '/shop/info/update', params)
export const shopAudit = (params: any) => request.post('/shop/info/audit', params)
export const shopStatusUpdate = (params: any) => request.post('/shop/info/update_status', params)
export const shopSimpleList = (params: any) => request.get('/shop/info/simple_list', {params: params})
export const shopUpdateRecommend = (params: any) => request.post('/shop/info/update_recommend', params);
export const shopUpdateHeepayMerchId = (params: any) => request.post('/shop/info/update_heepay_merch_id', params)
export const shopEntrySubmit = (id: number) => request.post('/shop/info/entry_submit/' + id);
export const shopEntryComplete = (id: number) => request.post('/shop/info/entry_complete/' + id);

/**
 * 店铺分类相关接口
 */
export const shopCategoryTreeList = (showDefault?: boolean) => request.get('/shop/category/tree_list', {params: {showDefault: showDefault}})
export const shopCategoryInfo = (id: number) => request.get('/shop/category/info/' + id)
export const shopCategorySaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/shop/category/create' : '/shop/category/update', params)
export const shopCategorySimpleList = (parentId: number, showDefault: boolean) => request.get('/shop/category/simple_list', {params: {parent_id: parentId, showDefault: showDefault}})

/**
 * 商品分类相关接口
 */
export const goodsCategoryTreeList = () => request.get('/shop/goods_category/tree_list')
export const goodsCategoryInfo = (id: number) => request.get('/shop/goods_category/info/' + id)
export const goodsCategorySaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/shop/goods_category/create' : '/shop/goods_category/update', params)
export const goodsCategorySimpleList = (parentId: number, showDefault: boolean) => request.get('/shop/goods_category/simple_list', {params: {parent_id: parentId, showDefault: showDefault}})

/**
 * 分类轮播图相关接口
 */
export const goodsCategoryImageList = (params: any) => request.get('/shop/goods_category_image/list', {params: params})
export const goodsCategoryImageInfo = (id: number) => request.get('/shop/goods_category_image/info/' + id)
export const goodsCategoryImageSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/shop/goods_category_image/create' : '/shop/goods_category_image/update', params)
export const goodsCategoryImageDelete = (id: number) => request.post('/shop/goods_category_image/delete/' + id)

/**
 * 商品模型接口
 */
export const modelList = (params: any) => request.get('/shop/goods_model/list', {params: params})
export const modelInfo = (id: number, params = {}) => request.get('/shop/goods_model/info/' + id, {params: params})
export const modelSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/shop/goods_model/create' : '/shop/goods_model/update', params)
export const modelUsableList = () => request.get('/shop/goods_model/usable_list')

/**
 * 商品接口
 */
export const goodsList = (params: any) => request.get('/shop/goods/list', {params: params})
export const goodsTabHeader = (params: any) => request.get('/shop/goods/tab_header', {params: params})
export const goodsInfo = (id: number) => request.get('/shop/goods/info/' + id)
export const goodsSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/shop/goods/create' : '/shop/goods/update', params)
export const goodsSaleStatusUpdate = (params: any) => request.post('/shop/goods/update_sale_status', params)
export const goodsAudit = (params: any) => request.post('/shop/goods/audit', params)
export const goodsDelete = (id: number) => request.post('/shop/goods/delete/' + id)
export const goodsRestore = (id: number) => request.post('/shop/goods/restore/' + id)
export const goodsUpdateRecommend = (params: any) => request.post('/shop/goods/update_recommend', params);
export const goodsUpdateOrderNum = (params: any) => request.post('/shop/goods/update_order_num', params);
export const goodsUpdateSalesCount = (params: any) => request.post('/shop/goods/update_sales', params);
export const goodsModifyStoreCount = (params: any) => request.post('/shop/goods/modify_store_count', params);
export const goodsBatchUpdate = (params: any) => request.post('/shop/goods/batch_update', params)
export const goodsSpecList = (id: number) => request.get('/shop/goods/spec_list/' + id)
export const goodsBatchStoreCount = (params: any) => request.post('/shop/goods/batch_update_store_count', params)

/**
 * 商品订单接口
 */
export const goodsOrderList = (params: any) => request.get('/shop/order/list', {params: params})
export const goodsOrderInfo = (id: number) => request.get('/shop/order/info/' + id)
export const orderDelivery = (params: any) => request.post('/shop/order/delivery', params)
export const orderRefund = (params: any) => request.post('/shop/order/refund', params)
export const orderTabHeader = (params: any) => request.get('/shop/order/tab_header', {params: params})

/**
 * 商品订单售后接口
 */
export const orderAfterSalesList = (params: any) => request.get('/shop/order_after_sales/list', {params: params})
export const orderAfterSalesInfo = (id: number) => request.get('/shop/order_after_sales/info/' + id)
export const orderAfterSalesVerify = (id: number) => request.post('/shop/order_after_sales/verify/' + id)
export const orderAfterSalesRecover = (id: number) => request.post('/shop/order_after_sales/recover/' + id)
export const orderAfterSalesAudit = (params: any) => request.post('/shop/order_after_sales/audit', params)

/**
 * 店铺区域推荐
 */
export const shopRegionRecommendList = (params: any) => request.get('/shop/region_recommend/list', {params: params})
export const shopRegionRecommendInfo = (id: number) => request.get('/shop/region_recommend/info/' + id)
export const shopRegionRecommendSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/shop/region_recommend/create' : '/shop/region_recommend/update', params)
export const shopRegionRecommendAll = () => request.get('/shop/region_recommend/all')


export type GoodsCategoryImage = {
  id: number;
  cate_id: number;
  type: number;
  status: number;
  image_url: string;
  jump_type: number;
  jump_content: string;
  jump_params: string;
  order_num: number;
};

export type GoodsModel = {
  id: number;
  shop_id: number;
  name: string;
  profile: string;
  status: number;
  spec_list: GoodsModelSpec[];
};

export type GoodsModelSpec = {
  id: number;
  model_id: number;
  name: string;
  status: number;
  order_num: number;
  spec_items: GoodsModelSpecItem[];
  select_ids: number[];
};

export type GoodsModelSpecItem = {
  id: number;
  model_spec_id: number;
  item: string;
  order_num: number;
};

export type GoodsInfo = {
  id: number;
  status: number;
  shop_id: number;
  model_id: number;
  cate_id?: number;
  type: number;
  mark_flag: number;
  certify_flag: number;
  name: string;
  cover_url: string;
  price_type: number;
  price: number;
  price_cost: number;
  price_integral: number;
  rebate_ratio: number;
  subsidy_ratio: number;
  promotion_ratio: number;
  service_fee_ratio: number;
  view_count: number;
  store_count: number;
  sales_count: number;
  buy_limit: number;
  not_shipped?: string;
  private_config_id?: number; // 私域配置编号
  order_num: number;
  audit_time?: string;
  audit_opinion?: string;
  subsidy_config_id: number;
  banner_list: GoodsImage[];
  content_list: GoodsImage[];
  spec_list: GoodsSpec[];
  not_shipped_list?: GoodsFreight[];
};

export type GoodsSpec = {
  id: number;
  goods_id: number;
  status?: number;
  spec_key: string;
  spec_key_name?: string;
  spec_key_ids?: number[];
  price?: number;
  price_cost?: number;
  price_integral?: number;
  store_count?: number;
  sales_count?: number;
  order_num?: number;
  update_type?: number;
  update_count?: number;
};

export type GoodsImage = {
  id?: number;
  goods_id?: number;
  type?: number;
  content: string;
  width?: number;
  height?: number;
  order_num: number;
};

export type GoodsFreight = {
  code: number;
  name: string;
  freight?: number;
};

export type TabHeaderData = {
  type: number;
  name: string;
  count: number;
};

export type ShopRegionRecommend = {
  id: number;
  name: string;
  cover_url: string;
  banner_data: string;
  enabled: boolean;
  order_num: number;
}

// 默认数据设置
export const defGoodsModel: GoodsModel = <GoodsModel>{id: 0, status: 1};
export const defGoodsInfo: GoodsInfo = <GoodsInfo>
  {
    id: 0,
    type: 1,
    status: 0,
    mark_flag: 0,
    price_type: 0,
    price: 0.00,
    price_cost: 0.00,
    price_integral: 0.00,
    rebate_ratio: 0.00,
    subsidy_ratio: 0.00,
    promotion_ratio: 0.00,
    service_fee_ratio: 0.00,
    certify_flag: 0,
    buy_limit: 0,
    order_num: 0
  };
